package cn.wolfcode.luowowo.controller;

import cn.wolfcode.luowowo.domain.Destination;
import cn.wolfcode.luowowo.query.DestinationQuery;
import cn.wolfcode.luowowo.service.IDestinationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


@Controller
@RequestMapping("destination")
public class DestinationController {

    @Autowired
    private IDestinationService destinationService;


    @RequestMapping("list")
    public String list(Model model, @ModelAttribute("qo") DestinationQuery qo,String parentId){

        // toasts
        // 通过 parentId  查看当前位置

        List<Destination> list = new ArrayList();

        // 通过parentId 递归获取层级关系
        List<Destination> toasts = destinationService.getToastsInfo(list,parentId);
        // 页面显示当前地址,顺序翻转
        // Collections.reverse(toasts);

        model.addAttribute("toasts",toasts);


        Page<Destination> page = destinationService.query(qo,parentId);
        model.addAttribute("page",page);

        return "destination/list";
    }



    

   

}
